<?php
/**
 * Created by PhpStorm.
 * User: sky
 * Date: 2019/7/16
 * Time: 23:04
 */

namespace App\Repositories;


use App\Models\GoodsBrand;

class BrandRepositories
{
    public function model()
    {
        return GoodsBrand::query();
    }

    public function find($id)
    {
        return $this->model()->where('id',$id)->first();
    }

    public function save($data)
    {
        return $this->model()->create($data);
    }
    public function update($id,$data)
    {
        return $this->model()->where('id',$id)->update($data);
    }

    public function search($data)
    {
        $model = $this->model();

        if(isset($data['name']))
        {
            $model = $model->where('title','like','%'.$data['name'].'%');
        }

        //些处扩展更多查询条件
        return $model->orderBy('created_at','desc')->paginate($data['limit'])->toArray();
    }

    public function delete($ids)
    {
        return GoodsBrand::destroy($ids);
    }

    public function allBrand()
    {
        return $this->model()->get()->toArray();
    }

}